package com.sino.dataworks.config;

import cn.hutool.setting.dialect.Props;
import com.alibaba.fastjson.JSON;
import com.sino.dataworks.job.*;
import com.sino.dataworks.util.JobVarUtil;
import com.sino.dataworks.util.QuartzManagerUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

import java.io.File;
import java.nio.charset.StandardCharsets;

@Component
@Slf4j
public class ApplicationInit implements ApplicationRunner {
    @Override
    public void run(ApplicationArguments args) throws Exception {
        log.info("启动后加载");
        // 0 0/10 0-7 * * ?
        // 0 0/10 * * * ? 每10分钟执行一次
        QuartzManagerUtil.addJob("dataworksPhoneWarningTask","dataworksPhoneWarningTask","dataworksPhoneWarningTask","dataworksPhoneWarningTask", DataworksPhoneWarningTask.class,"0 0/10 0-7 * * ?");
        //0 0 8 * * ?
        QuartzManagerUtil.addJob("dataworksInstanceLog","dataworksInstanceLog","dataworksInstanceLog","dataworksInstanceLog", DataworksInstanceLog.class,"0 0 8 * * ?");
        //0 30 8 * * ?
        QuartzManagerUtil.addJob("dataworksCheckColumnLog","dataworksCheckColumnLog","dataworksCheckColumnLog","dataworksCheckColumnLog", DataworksCheckColumnLog.class,"0 30 8 * * ?");
        // 每天下午1：30再监控一次
        QuartzManagerUtil.addJob("dataworksTaskMonitor","dataworksTaskMonitor","dataworksTaskMonitor","dataworksTaskMonitor", DataworksTaskMonitor.class,"0 30 13 * * ?");

        //0 0 18 ? * SUN
        QuartzManagerUtil.addJob("notifyTask","notifyTask","notifyTask","notifyTask", NotifyTask.class,"0 0 18 ? * SUN");
        QuartzManagerUtil.startJobs();
        QuartzManagerUtil.getJobDetail();
        Props props = new Props(new File("config.properties"), StandardCharsets.UTF_8);
        JobVarUtil.config=props;
        log.info("加载配置文件:"+ JSON.toJSONString(props));
    }
}
